package br.com.gsc.model.tableMapping;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

import org.springframework.transaction.annotation.Transactional;

@Entity
//@Table(name="admins")
@Transactional
public class Admin extends Person {

	private boolean superAdmin;

	 @ManyToMany(cascade = CascadeType.PERSIST)
	 @JoinTable(name = "COMPANY_PERSON",
				joinColumns = @JoinColumn(name = "username"),
				inverseJoinColumns = @JoinColumn(name = "company_id"))
     private List<Company> ListOfCompanies = new ArrayList<Company>();
	
	public Admin(){
		super(RoleUserType.ADMIN_ROLE);
	}
	 
	public boolean isSuperAdmin() {
		return superAdmin;
	}

	public void setSuperAdmin(boolean superAdmin) {
		this.superAdmin = superAdmin;
	}
	
	public List<Company> getListOfCompanies() {
		return ListOfCompanies;
	}

	public void setListOfCompanies(List<Company> listOfCompanies) {
		this.ListOfCompanies = listOfCompanies;
	}
	
	public void addCompany(Company comp){
		this.ListOfCompanies.add(comp);
	}		
	public void removeCompany(Company comp){
		this.ListOfCompanies.remove(comp);
	}
}

